'''
Created on 23/09/2012

@author: Charles
'''
import unittest
from Structural_Model.Parser import *
from Structural_Model.Container import *

class ParserTest(unittest.TestCase):


    def setUp(self):
        self.parser = Parser("Tests/StructuralModelTest.xml")
        self.parserLink = Parser("Tests/LinkTest.xml")


    def tearDown(self):
        pass


    def testParser(self):
        pass
    
    def testContainerParser(self):
        testContainer = Container("test", "xml", "xml", "test", "", "")
        self.assertIsNotNone(testContainer, "Cannot Create Container")
        root = self.parser.parse(self.parser.getRoot())
        container = root.getSubtree().getFirst()
        """
        for item in root.getSubtree():
            if item.getSubtree() != None:
                print item.getSubtree().getFirst().getMapping()
        """
        #print root.getSubtree().getFirst().getSubtree()
        #print root
        self.assertTrue(container.getMapping() == testContainer.getMapping(), "Failure value is {0}".format(container.getMapping()))
        self.assertTrue(container.getId() == "test")
        self.assertTrue(container.getSubtree().getFirst().getMapping() == "nothing")
        self.assertTrue(container.getSubtree().getFirst().getId() == "nothing")
    
    def testTag(self):
        pass
    
    def testLinkTags(self):
        model = self.parserLink.parse(self.parserLink.getRoot())
        self.parserLink.linkTags(model)
        self.assertTrue(model.getSubtree().getFirst().getSubtree().getFirst().getSubtree().getFirst().getLink() == model.getSubtree().getFirst())
        
    def testTraverseModel(self):
        model = self.parserLink.parse(self.parserLink.getRoot())
        next = self.parserLink.traverse(model, self.parser.getLinkList()[0])
        self.assertTrue(next.getLink() == model.getSubtree().getFirst(), "Traverse is not returning the right value.")
    
    def testGetRoot(self):
        root = self.parser.getRoot()
        self.assertTrue(root.tag == "model")

if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()